import type {  RolePermissionsType,  permissionsTreeType,  RoleItemType, RoleUserDataType, AddRoleParamsType } from "@/types/systemRole"
import { myGet, myPost, myRequest } from "@/utils/reuqest"

// 获取角色列表
export const getRoleListAPI = () => {
    return myGet<RoleItemType[]>('/park/sys/role')
}

// 获得权限树形结构
export const permissionsTreeAPI = () => {
    return myGet<permissionsTreeType[]>('/park/sys/permision/all/tree')
}

// 获取当前角色的权限和分配人数
export const getRolePermissionsAPI = (roleId: string) => {
    return myGet<RolePermissionsType>(`/park/sys/role/${roleId}`)
}

// 获取角色关联的用户列表
export const getRoleUserDataAPI = (roleId: string, params: { page: number, pageSize: number }) => {
    return myGet<RoleUserDataType>(`/park/sys/roleUser/${roleId}`, params)
}

// 添加角色
export const addRoleAPI = (data: AddRoleParamsType) => {
    return myPost('/park/sys/role', data)
}

// 编辑角色
export const editRoleAPI = (data: AddRoleParamsType, roleId: number) => {
    return myRequest({
        url: '/park/sys/role',
        method: 'PUT',
        data: { ...data, roleId }
    })
}

// 删除角色
export const deleteRoleAPI = (id: string) => {
    return myRequest({
        url: `/park/sys/role/${id}`,
        method: 'DELETE'
    })
}